Period picker
Allow users to select a range of dates quickly and intuitively.
#Examples
Default: Button shows selected range with presets available. Always has a default presets with the most commonly used date range.
Period picker consists of two main elements:
- Button (with clock icon) using two lines:
- Line 1: Active preset or custom date range.
- Line 2: Start and end dates of selected range
- Popover (triggered by button click) with:
- Preset tabs (e.g., "Last 7 Days," "Last Month")
- Interactive calendar view for custom range selection
const [period, setPeriod] = React.useState<PeriodPickerValue | null>({
start: new Date(2023, 4, 1),
end: new Date(2023, 4, 31),
type: PeriodType.Custom,
});
return (
<PeriodPicker
aria-label="Select period"
value={period}
onChange={setPeriod}
translations={translations}
/>
);
#Usage with hidden presets
Used when preset data is unavailable, focusing on custom selection.
const [period, setPeriod] = React.useState<PeriodPickerValue | null>({
start: new Date(2023, 4, 1),
end: new Date(2023, 4, 31),
type: PeriodType.Custom,
});
return (
<PeriodPicker
aria-label="Select period"
value={period}
onChange={setPeriod}
translations={translations}
hiddenPresets={[
PeriodType.LastSevenDays,
PeriodType.LastFourteenDays,
PeriodType.LastThirtyDays,
PeriodType.Last365Days,
]}
/>
);
#Usage with condensed variant
Button (with clock icon) displaying selected range in one line.
const [period, setPeriod] = React.useState<PeriodPickerValue | null>({
start: new Date(2023, 4, 1),
end: new Date(2023, 4, 31),
type: PeriodType.Custom,
});
return (
<PeriodPicker
aria-label="Select period"
value={period}
onChange={setPeriod}
translations={translations}
condensed
/>
);
#Properties
Property | Description | Defined | Value |
---|---|---|---|
translationsRequired | object | ||
valueRequired | | object The value of the component | ||
onChangeRequired | function Callback that is called when the value changes | ||
minDateOptional | date | ||
maxDateOptional | date | ||
literal-union[] | |||
condensedOptional | boolean | ||
disabledOptional | boolean Whether the component is disabled | ||
aria-labelOptional | string Label of the form control | ||
aria-describedbyOptional | string ID of an an element that describes what the form control is for | ||
aria-labelledbyOptional | string ID of an an element that labels this form control | ||
periodButtonStyleOptional | object Add inline style for the button only if necessary | ||
strategyOptional | "absolute" | "fixed" Position popover using fixed or absolute | ||
data-observe-keyOptional | string Unique string, used by external script e.g. for event tracking | ||
classNameOptional | string Custom className that's applied to the outermost element (only intended for special cases) | ||
styleOptional | object Style object to apply custom inline styles (only intended for special cases) | ||
tabIndexOptional | number Tab index of the outermost HTML element of the component | ||
onKeyDownOptional | function Callback for onKeyDown event | ||
onMouseDownOptional | function Callback for onMouseDown event | ||
onMouseEnterOptional | function Callback for onMouseEnter event | ||
onMouseLeaveOptional | function Callback for onMouseLeave event | ||
onFocusOptional | function Callback for onFocus event | ||
onBlurOptional | function Callback for onBlur event |
#Guidelines
#Best practices
#Do not use when
#Accessibility
Explore detailed guidelines for this component: Accessibility Specifications